﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Dynamic;
using System.Text;
using Hotnet.Entity;
using Hotnet.Dal.BaseRepository;
using Hotnet.Entity.Search;

namespace Hotnet.Dal.NSDalMusic
{
	public class DalMusic : Repository<Music>
	{
		public Music[] ListMusicByCategoryID(int categoryId, int pageNo, int pageSize, out int totalSize, SearchMusicCondition smc)
		{
			var query = (from music in disableCacheDataContext.Music
						 where music.CategoryID == categoryId && music.Name.Contains(smc.Name ?? "") && music.Stars.Contains(smc.StarName ?? "")
						 orderby music.AddTime descending
						 select music).Skip(pageNo * pageSize).Take(pageSize);

			totalSize = (from music in disableCacheDataContext.Music
						 where music.CategoryID == categoryId && music.Name.Contains(smc.Name ?? "") && music.Stars.Contains(smc.StarName ?? "")
						 select music).Count();

			return query.ToArray();

		}

		public Music[] ListMusicByGroupID(int groupId, SearchMusicCondition smc)
		{
			var query = (from music in disableCacheDataContext.Music
						 join mgxm in disableCacheDataContext.MusicGroupXMusic
						 on music.MusicID equals mgxm.MusicID
						 where mgxm.GroupID == groupId && music.Name.Contains(smc.Name ?? "") && music.Stars.Contains(smc.StarName ?? "")
						 orderby music.AddTime descending
						 select music);
			return query.ToArray();
		}
	}
}
